package com.maxmlr.mybatisplus.common.resut;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxmlr.mybatisplus.common.bean.Bean;

public class PageBean extends Bean {
	private static final long serialVersionUID = 1L;

	/**
	 * 当前页
	 */
	private int pageNum = 1;
	/**
	 * 显示记录数
	 */
	private int pageSize = 10;
	/**
	 * 总页数
	 */
	private int pageCount = 0;
	/**
	 * 总记录数
	 */
	private int rowCount = 0;
	/**
	 * 排序字段
	 */
	private String sort;

	public PageBean() {
	}

	/**
	 * 
	 * @param pageNum
	 *            当前页
	 * @param pageSize
	 *            显示记录数
	 */
	public PageBean(int pageNum, int pageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
	}
	
	public PageBean(Page<?> page) {
		this.pageNum = (int) page.getCurrent();
		this.pageSize = (int) page.getSize();
		this.rowCount = (int) page.getTotal();
		setPageCount();
	}

	/**
	 * 
	 * @param pageNum
	 *            当前页
	 * @param pageSize
	 *            显示记录数
	 * @param rowCount
	 *            总记录数
	 */
	public PageBean(int pageNum, int pageSize, int rowCount) {
		this.pageSize = pageSize;
		this.pageNum = pageNum;
		this.rowCount = rowCount;
		setPageCount();
	}
	
	public void setPageCount() {
		this.pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

}
